package main

import "fmt"

// 定义支付策略接口
type PaymentStrategy interface {
	Pay(amount float64) string
}

// 支付宝支付策略
type AlipayStrategy struct{}

func (a *AlipayStrategy) Pay(amount float64) string {
	return fmt.Sprintf("Paid %.2f using Alipay", amount)
}

// 微信支付策略
type WechatPayStrategy struct{}

func (w *WechatPayStrategy) Pay(amount float64) string {
	return fmt.Sprintf("Paid %.2f using Wechat Pay", amount)
}

// 银行卡支付策略
type BankCardStrategy struct{}

func (b *BankCardStrategy) Pay(amount float64) string {
	return fmt.Sprintf("Paid %.2f using Bank Card", amount)
}

// 支付策略工厂
type PaymentStrategyFactory struct{}

func (f *PaymentStrategyFactory) GetStrategy(paymentMethod string) PaymentStrategy {
	switch paymentMethod {
	case "alipay":
		return &AlipayStrategy{}
	case "wechat":
		return &WechatPayStrategy{}
	case "bankcard":
		return &BankCardStrategy{}
	default:
		return nil
	}
}

// 支付上下文
type PaymentContext struct {
	strategy PaymentStrategy
}

func (c *PaymentContext) SetStrategy(strategy PaymentStrategy) {
	c.strategy = strategy
}

func (c *PaymentContext) ExecutePayment(amount float64) string {
	if c.strategy == nil {
		return "No payment strategy set"
	}
	return c.strategy.Pay(amount)
}

func main() {
	// 创建支付策略工厂
	factory := &PaymentStrategyFactory{}

	// 创建支付上下文
	context := &PaymentContext{}

	// 使用支付宝支付
	context.SetStrategy(factory.GetStrategy("alipay"))
	fmt.Println(context.ExecutePayment(100.0)) // 输出: Paid 100.00 using Alipay

	// 使用微信支付
	context.SetStrategy(factory.GetStrategy("wechat"))
	fmt.Println(context.ExecutePayment(200.0)) // 输出: Paid 200.00 using Wechat Pay

	// 使用银行卡支付
	context.SetStrategy(factory.GetStrategy("bankcard"))
	fmt.Println(context.ExecutePayment(300.0)) // 输出: Paid 300.00 using Bank Card

	// 使用不支持的支付方式
	context.SetStrategy(factory.GetStrategy("unknown"))
	fmt.Println(context.ExecutePayment(400.0)) // 输出: No payment strategy set
}
